﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Configuration;
using PeachLite.Entity;

namespace PeachLite.Helpers
{
    public static class ConfigHelper
    {
        public static Config Config { get; set; }

        private const char SPLIT_TIEM = ',';
        private const string ICONS = "ICons";
        private const string IMAGETYPES = "ImageTypes";
        private const string ICONEXTENSION = "IconExtension";
        private const string ICONPATH = "IconPath";
        private const string DEFAULTFILEICON = "DefaultFileIcon";
        private const string DEFAULTFOLDERICON = "DefaultFolderIcon";
        private const string DEFAULTPATH = "DefaultPath";
        private const string FILETEMPPATH = "FileTempPath";
        private const string TITLEIMAGEPATH = "TitleImagePath";
        private const string ARTICLEIMAGEPATH = "ArticleImagePath";
        private const string DEFAULTIMAGE = "DefaultImage";
        private const string FOLDEREMPTY = "FolderEmpty";
        private const string FOLDERHASFILE = "FolderHasFile";
        private const string FOLDERHASFOLDER = "FolderHasFolder";

        public static void Load()
        {
            Config = new Config();

            //获得图标
            Config.Icons = string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings[ICONS]) ? new string[0] : ConfigurationManager.AppSettings[ICONS].Split(SPLIT_TIEM);

            //获得图片类型
            Config.ImageTypes = string.IsNullOrWhiteSpace(ConfigurationManager.AppSettings[IMAGETYPES]) ? new string[0] : ConfigurationManager.AppSettings[IMAGETYPES].Split(SPLIT_TIEM);

            //获得图标后缀
            Config.IconExtension = ConfigurationManager.AppSettings[ICONEXTENSION] == null ? "" : ConfigurationManager.AppSettings[ICONEXTENSION].Trim();

            //获得图标路径
            Config.IconPath = ConfigurationManager.AppSettings[ICONPATH] == null ? "" : ConfigurationManager.AppSettings[ICONPATH].Trim();

            //获得默认图标
            Config.DefaultFileIcon = ConfigurationManager.AppSettings[DEFAULTFILEICON] == null ? "" : ConfigurationManager.AppSettings[DEFAULTFILEICON].Trim();

            //获得默认文件夹图标
            Config.DefaultFolderIcon = ConfigurationManager.AppSettings[DEFAULTFOLDERICON] == null ? "" : ConfigurationManager.AppSettings[DEFAULTFOLDERICON].Trim();

            //获得默认路径
            Config.DefaultPath = ConfigurationManager.AppSettings[DEFAULTPATH] == null ? "" : ConfigurationManager.AppSettings[DEFAULTPATH].Trim();

            //获得临时文件保存路径
            Config.FileTempPath = ConfigurationManager.AppSettings[FILETEMPPATH] == null ? "" : ConfigurationManager.AppSettings[FILETEMPPATH].Trim();

            //获得标题图片保存路径
            Config.TitleImagePath = ConfigurationManager.AppSettings[TITLEIMAGEPATH] == null ? "" : ConfigurationManager.AppSettings[TITLEIMAGEPATH].Trim();

            //获得文章相关图片保存路径
            Config.ArticleImagePath = ConfigurationManager.AppSettings[ARTICLEIMAGEPATH] == null ? "" : ConfigurationManager.AppSettings[ARTICLEIMAGEPATH].Trim();

            //获得默认图片
            Config.DefaultImage = ConfigurationManager.AppSettings[DEFAULTIMAGE] == null ? "" : ConfigurationManager.AppSettings[DEFAULTIMAGE].Trim();

            //获得空文件夹图标
            Config.FolderEmpty = ConfigurationManager.AppSettings[FOLDEREMPTY] == null ? "" : ConfigurationManager.AppSettings[FOLDEREMPTY].Trim();

            //获得包含文件的文件夹图标
            Config.FolderHasFile = ConfigurationManager.AppSettings[FOLDERHASFILE] == null ? "" : ConfigurationManager.AppSettings[FOLDERHASFILE].Trim();

            //获得包含文件夹的文件夹图标
            Config.FolderHasFolder = ConfigurationManager.AppSettings[FOLDERHASFOLDER] == null ? "" : ConfigurationManager.AppSettings[FOLDERHASFOLDER].Trim();
        }

        static ConfigHelper()
        {
            Load();
        }
    }
}